<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class WebCtrl extends CI_Controller {
	   function __construct()
    {
        parent::__construct();
    	$this->load->library('session');
		$this->load->database();
    	$this->load->model("webmod");
    	$this->load->helper(array('form', 'url'));
    }
    
   //group 
//------ menu------------------   
 function web_adminmenu()
 	{
 		$data=array();
 		$data['listgroup']=$this->webmod-> getlistegroup();
 		$data['listewebtours']=$this->webmod-> getlistewebtours();
 		$data["listfeatures"]=$this->webmod->listfeatures();
 		$this->load->view("web/menu",$data);
 		
	 }   
    
	 
//---- end menu ----------------	 
   function pg_addgroup()
   {
   		if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
   				//$group=$this->webmod->getgroupbyid($idgroup);
				$data=array("act"=>"add");
				$this->load->view("web/group",$data);
			
			}
   } // pg_addgroup
    

  function subgroup()
  {
  		if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
			
				$data["name_en"]=$this->input->get_post("name_en");
				$data["name_fr"]=$this->input->get_post("name_fr");
				$data["name_cn"]=$this->input->get_post("name_cn");
				$data["desc_en"]=$this->input->get_post("desc_en");
				$data["desc_fr"]=$this->input->get_post("desc_fr");
				$data["desc_cn"]=$this->input->get_post("desc_cn");
				$data["sector"]=$this->input->get_post("sector");
				$idinsert=$this->webmod-> insertetemplate("web_group",$data);
				redirect("index.php?webctrl/pg_addgroup","refresh");
			}
   }
  function edit_group()
  	{
  		if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
		  		$idweb_group=$this->input->get_post("idweb_group");
		  		$data=array();	
		  		$data["groupcontent"]=$this->webmod->getgroupbyid($idweb_group);
		  		$data["act"]="edit";
		  		$this->load->view("web/group",$data);  				
			}		
	}
	
	function sub_editgroup() 
	{
		if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				$data["idweb_group"]=$this->input->get_post("idweb_group");
				$data["name_en"]=$this->input->get_post("name_en");
				$data["name_fr"]=$this->input->get_post("name_fr");
				$data["name_cn"]=$this->input->get_post("name_cn");
				$data["desc_en"]=$this->input->get_post("desc_en");
				$data["desc_fr"]=$this->input->get_post("desc_fr");
				$data["desc_cn"]=$this->input->get_post("desc_cn");
				$data["sector"]=$this->input->get_post("sector");
				$idweb_group=$data["idweb_group"];
				$where="idweb_group=$idweb_group";
				$idinsert=$this->webmod-> updatetemplate("web_group",$data,$where);
				redirect("index.php?webctrl/web_adminmenu","refresh");
			}
	}
	
//------------ webtours admin-----------------
	
	 function pg_addwebtours()
	   {
	   		if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
				{
						header('Location:index.php?pages/loginadmin');
							
				}else 
				{
	   				//$group=$this->webmod->getgroupbyid($idgroup);
					$data['listgroup']=$this->webmod-> getlistegroup();
					$data["act"]="add";
					$this->load->view("web/webtours",$data);
				
				}
	   } // pg_addgroup
	    
	
	function sub_webtours() 
	{
		if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				$data["web_group_idweb_group"]=$this->input->get_post("web_group_idweb_group");
				$data["name_en"]=$this->input->get_post("name_en");
				$data["name_fr"]=$this->input->get_post("name_fr");
				$data["name_cn"]=$this->input->get_post("name_cn");
				$data["subtitle_en"]=$this->input->get_post("subtitle_en");
				$data["subtitle_fr"]=$this->input->get_post("subtitle_fr");
				$data["subtitle_cn"]=$this->input->get_post("subtitle_cn");
				$data["desc_en"]=$this->input->get_post("desc_en");
				$data["desc_fr"]=$this->input->get_post("desc_fr");
				$data["desc_cn"]=$this->input->get_post("desc_cn");
				$data["price_r"]=$this->input->get_post("price_r");
				$data["price_red"]=$this->input->get_post("price_red");
				$data["place_dispo"]=$this->input->get_post("place_dispo");
				$data["bookingcode"]=$this->input->get_post("bookingcode");
				$data["with_room"]=$this->input->get_post("with_room");
				$idinsert=$this->webmod-> insertetemplate("web_travel",$data);
				$data1["web_travel_idweb_travel"]=$idinsert;
				if($data["with_room"]==1)
				{
				$data1["reg_1"]=$this->input->get_post("reg_1")!=""?$this->input->get_post("reg_1"):0;
				$data1["reg_2"]=$this->input->get_post("reg_2")!=""?$this->input->get_post("reg_2"):0;
				$data1["reg_3"]=$this->input->get_post("reg_3")!=""?$this->input->get_post("reg_3"):0;
				$data1["reg_4"]=$this->input->get_post("reg_4")!=""?$this->input->get_post("reg_4"):0;
				$data1["reg_child"]=$this->input->get_post("reg_child")!=""?$this->input->get_post("reg_child"):0;
				
				$data1["line_1"]=$this->input->get_post("line_1")!=""?$this->input->get_post("line_1"):0;
				$data1["line_2"]=$this->input->get_post("line_2")!=""?$this->input->get_post("line_2"):0;
				$data1["line_3"]=$this->input->get_post("line_3")!=""?$this->input->get_post("line_3"):0;
				$data1["line_4"]=$this->input->get_post("line_4")!=""?$this->input->get_post("line_4"):0;
				$data1["line_child"]=$this->input->get_post("line_child")!=""?$this->input->get_post("line_child"):0;
				
				$data1["member_1"]=$this->input->get_post("member_1")!=""?$this->input->get_post("member_1"):0;
				$data1["member_2"]=$this->input->get_post("member_2")!=""?$this->input->get_post("member_2"):0;
				$data1["member_3"]=$this->input->get_post("member_3")!=""?$this->input->get_post("member_3"):0;
				$data1["member_4"]=$this->input->get_post("member_4")!=""?$this->input->get_post("member_4"):0;
				$data1["member_child"]=$this->input->get_post("member_child")!=""?$this->input->get_post("member_child"):0;
				$idinsert_priceroom=$this->webmod-> insertetemplate("with_room_price",$data1);
				
				}
					elseif ($data["with_room"]=="")
						{
							$data1["reg_child_1"]=$this->input->get_post("reg_child_1")!=""?$this->input->get_post("reg_child_1"):0;
							$data1["line_child_1"]=$this->input->get_post("line_child_1")!=""?$this->input->get_post("line_child_1"):0;
							$data1["member_child_1"]=$this->input->get_post("member_child_1")!=""?$this->input->get_post("member_child_1"):0;
							
							$data1["reg_ad"]=$this->input->get_post("reg_ad")!=""?$this->input->get_post("reg_ad"):0;
							$data1["line_ad"]=$this->input->get_post("line_ad")!=""?$this->input->get_post("line_ad"):0;
							$data1["member_ad"]=$this->input->get_post("member_ad")!=""?$this->input->get_post("member_ad"):0;
							$idinsert_priceroom=$this->webmod-> insertetemplate("with_room_price",$data1);
						}
						
				
				
				redirect("index.php?webctrl/pg_addwebtours","refresh");
			}
	}
	
	
 function edit_webtours()
  	{
  		if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
		  		$idweb_travel=$this->input->get_post("idweb_travel");
		  		$data=array();
		  		$data['listgroup']=$this->webmod-> getlistegroup();	
		  		$data["webtourscontent"]=$this->webmod->getwebtourswithpricebyid($idweb_travel);
		  		$data["act"]="edit";
		  		$this->load->view("web/webtours",$data);  				
			}		
	}
	

function sub_editwebtours() 
	{
		if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				
				
				$data["web_group_idweb_group"]=$this->input->get_post("web_group_idweb_group");
				$data["name_en"]=$this->input->get_post("name_en");
				$data["name_fr"]=$this->input->get_post("name_fr");
				$data["name_cn"]=$this->input->get_post("name_cn");
				$data["subtitle_en"]=$this->input->get_post("subtitle_en");
				$data["subtitle_fr"]=$this->input->get_post("subtitle_fr");
				$data["subtitle_cn"]=$this->input->get_post("subtitle_cn");
				$data["desc_en"]=$this->input->get_post("desc_en");
				$data["desc_fr"]=$this->input->get_post("desc_fr");
				$data["desc_cn"]=$this->input->get_post("desc_cn");
				$data["price_r"]=$this->input->get_post("price_r");
				$data["price_red"]=$this->input->get_post("price_red");
				$data["place_dispo"]=$this->input->get_post("place_dispo");
				$data["bookingcode"]=$this->input->get_post("bookingcode");
				$data["with_room"]=$this->input->get_post("with_room");
				$idtravel=$this->input->get_post("idweb_travel");
				$where="idweb_travel=$idtravel";
				$idinsert=$this->webmod-> updatetemplate("web_travel",$data,$where);
				
				$data1["web_travel_idweb_travel"]=$idtravel;
				$idwith_room_price=$this->input->get_post("idwith_room_price");
				
				
		//------------------intial le tous le champ de price -------------------
				$data_null["reg_1"]=0;
				$data_null["reg_2"]=0;
				$data_null["reg_3"]=0;
				$data_null["reg_4"]=0;
				$data_null["reg_child"]=0;
				$data_null["line_1"]=0;
				$data_null["line_2"]=0;
				$data_null["line_3"]=0;
				$data_null["line_4"]=0;
				$data_null["line_child"]=0;
				$data_null["member_1"]=0;
				$data_null["member_2"]=0;
				$data_null["member_3"]=0;
				$data_null["member_4"]=0;
				$data_null["member_child"]=0;
				$data_null["reg_child"]=0;
				$data_null["line_child"]=0;
				$data_null["member_child"]=0;
				$data_null["reg_ad"]=0;
				$data_null["line_ad"]=0;
				$data_null["member_ad"]=0;
				$data_null["reg_child_1"]=0;
				$data_null["member_child_1"]=0;
				$data_null["line_child_1"]=0;
				$where_null="idwith_room_price=$idwith_room_price";
				$idinsert_priceroom_null=$this->webmod-> updatetemplate("with_room_price",$data_null,$where_null);
				
				if($data["with_room"]==1)
				{
				$data1["reg_1"]=$this->input->get_post("reg_1")!=""?$this->input->get_post("reg_1"):0;
				$data1["reg_2"]=$this->input->get_post("reg_2")!=""?$this->input->get_post("reg_2"):0;
				$data1["reg_3"]=$this->input->get_post("reg_3")!=""?$this->input->get_post("reg_3"):0;
				$data1["reg_4"]=$this->input->get_post("reg_4")!=""?$this->input->get_post("reg_4"):0;
				$data1["reg_child"]=$this->input->get_post("reg_child")!=""?$this->input->get_post("reg_child"):0;
				
				$data1["line_1"]=$this->input->get_post("line_1")!=""?$this->input->get_post("line_1"):0;
				$data1["line_2"]=$this->input->get_post("line_2")!=""?$this->input->get_post("line_2"):0;
				$data1["line_3"]=$this->input->get_post("line_3")!=""?$this->input->get_post("line_3"):0;
				$data1["line_4"]=$this->input->get_post("line_4")!=""?$this->input->get_post("line_4"):0;
				$data1["line_child"]=$this->input->get_post("line_child")!=""?$this->input->get_post("line_child"):0;
				
				$data1["member_1"]=$this->input->get_post("member_1")!=""?$this->input->get_post("member_1"):0;
				$data1["member_2"]=$this->input->get_post("member_2")!=""?$this->input->get_post("member_2"):0;
				$data1["member_3"]=$this->input->get_post("member_3")!=""?$this->input->get_post("member_3"):0;
				$data1["member_4"]=$this->input->get_post("member_4")!=""?$this->input->get_post("member_4"):0;
				$data1["member_child"]=$this->input->get_post("member_child")!=""?$this->input->get_post("member_child"):0;
				$where1="idwith_room_price=$idwith_room_price";
				$idinsert_priceroom=$this->webmod-> updatetemplate("with_room_price",$data1,$where1);
				
				}
					elseif ($data["with_room"]=="")
						{
							$data1["reg_child_1"]=$this->input->get_post("reg_child_1")!=""?$this->input->get_post("reg_child_1"):0;
							$data1["line_child_1"]=$this->input->get_post("line_child_1")!=""?$this->input->get_post("line_child_1"):0;
							$data1["member_child_1"]=$this->input->get_post("member_child_1")!=""?$this->input->get_post("member_child_1"):0;
							
							$data1["reg_ad"]=$this->input->get_post("reg_ad")!=""?$this->input->get_post("reg_ad"):0;
							$data1["line_ad"]=$this->input->get_post("line_ad")!=""?$this->input->get_post("line_ad"):0;
							$data1["member_ad"]=$this->input->get_post("member_ad")!=""?$this->input->get_post("member_ad"):0;
							$where1="idwith_room_price=$idwith_room_price";
							$idinsert_priceroom=$this->webmod-> updatetemplate("with_room_price",$data1,$where1);
						}
						
				
				
				redirect("index.php?webctrl/web_adminmenu","refresh");
			}
	}
	
	

	
function edit_featurespos()
	{
			if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				
				$this->webmod->initalfeatures();
				for($i=1;$i<=6;$i++)
				{
					
					if($this->input->get_post("pos_$i")!=0)
					{
						$data["featureshowitems"]=$i;
						$idweb_travel=$this->input->get_post("pos_$i");
						$where="idweb_travel=$idweb_travel";
						$this->webmod-> updatetemplate("web_travel",$data,$where);
					}
				}
				redirect("index.php?webctrl/web_adminmenu","refresh");
			}
	}
	
function edit_webtoursimage()
{
	
	
			if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
	$data["idweb_travel"]=$this->input->get_post("idweb_travel");
	$data["webtourscontent"]=$this->webmod->getwebtourswithpricebyid($data["idweb_travel"]);
	$data['error']="";
	$this->load->view('web/webtoursimage', $data);
			}
}
	
function upload()
{
	
			if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
		$data["idweb_travel"]=$this->input->get_post("idweb_travel");
		$data["webtourscontent"]=$this->webmod->getwebtourswithpricebyid($data["idweb_travel"]);
		$config['upload_path'] = './ssh';
		$config['file_name']="webtours-".$data["idweb_travel"];
		$config['allowed_types'] = 'jpg';
		$config['max_size']	= '500';
		$config['max_width']  = '1010';
		$config['max_height']  = '330';
		$config['overwrite']=true;

		$this->load->library('upload', $config);

		if ( ! $this->upload->do_upload('images'))
		{
			$data["error"] = array('error' => $this->upload->display_errors());
			
			$this->load->view('web/webtoursimage', $data);
		}
		else
		{
			//$data = array('upload_data' => $this->upload->data());
			//print_r($data);
			$data["error"]="image is uploaded";
			//$this->load->view('upload_success', $data);
			$this->load->view('web/webtoursimage', $data);
		}
		
     }	
}

function delwebtour()
{
	
			if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
		$idtours=$this->input->get_post("idweb_travel");
		if($idtours!="")
		{
			$this->webmod->deletewebtour($idtours);
		}
		redirect("index.php?webctrl/web_adminmenu","refresh");
		
			}
}

// webtext

function webtext()
{
	
			if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				$textcode=$this->input->get_post("textcode");
				$content_array=$this->webmod->getwebtext($textcode);
				$data=array("textcode"=>$textcode,"content"=>$content_array);
				$this->load->view("web/webtext",$data);
			}
}

function addwebtext()
{
	
			if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
							{
								$data["textcode"]=$this->input->get_post("textcode");
								$data["content_en"]=$this->input->get_post("content_en");
								$data["content_fr"]=$this->input->get_post("content_fr");
								$data["content_cn"]=$this->input->get_post("content_cn");
								$idinsert=$this->webmod-> insertetemplate("web_texts",$data);
								redirect("index.php?webctrl/web_adminmenu","refresh");
	
			}
}

function editwebtext()
{
	
			if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
	
				$textcode=trim($this->input->get_post("textcode"));
				$data["content_en"]=$this->input->get_post("content_en");
				$data["content_fr"]=$this->input->get_post("content_fr");
				$data["content_cn"]=$this->input->get_post("content_cn");
				$idinsert=$this->webmod-> updatetemplate("web_texts",$data,"textcode='$textcode'");
				redirect("index.php?webctrl/web_adminmenu","refresh");
	
			}
}


    
}